package com.party.course.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.enums.BusinessType;
import com.party.common.utils.poi.ExcelUtil;
import com.party.course.domain.StudentInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.course.service.IStudentInfoService;
import com.party.common.core.page.TableDataInfo;

/**
 * 学员信息Controller
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/course/Student")
public class StudentInfoController extends BaseController {
    @Autowired
    private IStudentInfoService studentInfoService;

    /**
     * 查询学员信息列表
     */
//@RequiresPermissions("course:Student:list")
    @GetMapping("/list")
    public TableDataInfo list(StudentInfo studentInfo) {

        List<StudentInfo> list = studentInfoService.findList(studentInfo);
        return getDataTable(list);
    }
    @GetMapping("/listxcx")
    public TableDataInfo listxcx(StudentInfo studentInfo) {

        List<StudentInfo> list = studentInfoService.findList(studentInfo);
        return getDataTable(list);
    }

    @GetMapping("/all")
    public TableDataInfo all(StudentInfo studentInfo) {

        List<StudentInfo> list = studentInfoService.findAll(studentInfo);
        return getDataTable(list);
    }

    /**
     * 导出学员信息列表
     */
    //@RequiresPermissions("course:Student:export")
    @Log(title = "学员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentInfo studentInfo) {
        List<StudentInfo> list = studentInfoService.findList(studentInfo);
        ExcelUtil<StudentInfo> util = new ExcelUtil<StudentInfo>(StudentInfo.class);
        util.exportExcel(response, list, "学员信息数据");
    }

    /**
     * 获取学员信息详细信息
     */
    //@RequiresPermissions("course:Student:query")
    @GetMapping(value = "/view/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(studentInfoService.view(id));
    }

    /**
     * 新增学员信息
     */
    //@RequiresPermissions("course:Student:add")
    @Log(title = "学员信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody StudentInfo studentInfo) {
        return toAjax(studentInfoService.add(studentInfo));
    }

    /**
     * 修改学员信息
     */
    //@RequiresPermissions("course:Student:edit")
    @Log(title = "学员信息", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody StudentInfo studentInfo) {
        return toAjax(studentInfoService.updateEntity(studentInfo));
    }
    @PutMapping("/updateTk")
    public AjaxResult updateTk(@RequestBody StudentInfo studentInfo) {
        return toAjax(studentInfoService.updateEntityTk(studentInfo));
    }

    /**
     * 删除学员信息
     */
    //@RequiresPermissions("course:Student:remove")
    @Log(title = "学员信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(studentInfoService.deleteIds(Arrays.asList(ids)));
    }

    /**
     * 分配学管
     * @param ids
     * @param learnId
     * @return
     */
    @GetMapping("/setLearnId/{ids}")
    public AjaxResult setLearnId(@PathVariable String[] ids, String learnId) {
        return toAjax(studentInfoService.setLearnId(Arrays.asList(ids), learnId));
    }
}
